package com.sprd.simple.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.sprd.simple.launcher.R;
import com.sprd.simple.model.IconInfo;

import java.util.List;

/**
 * Created by SPRD on 2016/7/19.
 */
public class ToolsItemAdapter extends BaseListViewAdapter<IconInfo> {

    private final static String TAG = "ToolsItemAdapter";
    private String[] appNameForTTS;

    public ToolsItemAdapter(Context context, List<IconInfo> icons, String[] appName) {
        super(context, icons);
        appNameForTTS = appName;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        IconHolder iconHolder = null;
        if (convertView == null) {
            iconHolder = new IconHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.tools_app_item_appliction, null);
            iconHolder.iconName = (TextView) convertView.findViewById(R.id.list_item_name_icon);
            iconHolder.iconImage = (ImageView) convertView.findViewById(R.id.list_item_image_icon);
            convertView.setTag(iconHolder);
        } else {
            iconHolder = (IconHolder) convertView.getTag();
        }

        iconHolder.iconName.setText(mInfos.get(position).getIconName());
        iconHolder.iconImage.setImageResource(mInfos.get(position).getIconImage());

        if (mPosition == position) {
            convertView.setBackgroundColor(mContext.getResources().getColor(R.color.selected_list_color));
            Log.d(TAG, "read() tools ");
        } else {
            convertView.setBackgroundColor(mContext.getResources().getColor(R.color.app_name_color));
        }

        return convertView;
    }

    public class IconHolder {
        private TextView iconName;
        private ImageView iconImage;
    }

}
